// miniprogram/pages/deviceControl/tempHumi/index.js
const { request } = require('../../API/request');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    alarm_temp_max:0,  //温度告警值
    temp_value: 0,  //温度
    humi_value:0,  //湿度
    input_value:'',
    gradientColor: {  //渐变色
      '0%': 'skyblue',
      '100%': '#ee0a24',
    },
    deviceInfo:{},
    deviceId:'',
    AliasName:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getData();
  },

  // 获取上一页传递来的数据
  getData:function(){
    let that = this;
    const eventChannel = that.getOpenerEventChannel();
    eventChannel.on('getDeviceInfo',function(data){
      that.setData({
        deviceId:data.deviceId
      });
      that.getDeviceDetail(data.deviceId)
    });
  },


  async getDeviceDetail(deviceId){
    const res = await request(`system/device/${deviceId}`,'get');
    console.log("设备详情",res);
    if (res.code === 200) {
      this.setData({
        deviceInfo:res.data
      })
    }
  },
  lookDetail(e){
    wx.navigateTo({
      url: '/pages/deviceDetail/index',
      success: (result) => {
        result.eventChannel.emit('getDeviceInfo',e.currentTarget.dataset.info)
      }
    })
  },

  
 //输入框输入事件
  onChange(e){
    this.setData({ input_value:e.detail })
  },
 
})